package com.example.haosiji.app;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.baidu.mapapi.BMapManager;
import com.example.haosiji.maps.locationManager;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.widget.Toast;

public class haosijiApp extends Application{

	private BMapManager mBMapMan = null;
	private List<Activity> mList = new LinkedList();
	
	public void onCreate(){
			
		mBMapMan = new BMapManager(getApplicationContext());
		mBMapMan.init("ytqgNNlC2k7EsS0nFuTPXXSK",null);
		
		AppInfo.mApp = this;
		
		AppInfo.BASE_DATA_DIR = this.getFilesDir().getPath();
		DBManager.initDataBase(this);
		
//		DBManager.saveDriverInfo("peng", "15001808289", System.currentTimeMillis());
		
	}
	
	public BMapManager getmBMapMan() {
		return mBMapMan;
	}
	
	public void addActivity(Activity paramActivity) {
		mList.add(paramActivity);
	}
	
	public void removeActivity(Activity paramActivity) {
		mList.remove(paramActivity);
	}
	
	private void finishAllActivities() {
		try {
			Iterator localIterator = this.mList.iterator();
			while (true) {
				if (!localIterator.hasNext())
					return;
				Activity localActivity = (Activity) localIterator.next();
				if (localActivity != null)
					localActivity.finish();
			}
		} catch (Exception localException) {
			localException.printStackTrace();
		}
	}
	
	public void exit() {
		if (mBMapMan != null) {
			mBMapMan.destroy();
			mBMapMan = null;
		}	
		finishAllActivities();
		System.exit(0);
	}
	
	
	public void checkConnection(){
		
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		
		NetworkInfo info = cm.getActiveNetworkInfo();
		if(info == null){
			Toast.makeText(this, "网络未连接，请检查网络状态！", Toast.LENGTH_SHORT).show();
			return;
		}
	}
	
	
	
	
}
